package com.tigerlee.candle.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class SharedPreference {
	private static String NAME_PREFERENCE[] = {
        "tipdialog",
        "language",
        "chatname",
        "chat_default"
	};
	private Context mContext;
    public SharedPreferences mPreferences;
    
    public static String PREFERENCE_NAME = "preferencedata";
    public static int PREFERENCE_MODE = Activity.MODE_PRIVATE;
    
    public static String TAG = "Shared_Preference";
    
    public SharedPreference(Context context) {
            mContext= context;
    }
    public SharedPreferences getCustomSharedPreferences(){
            //get SharedData to save in xml 
            SharedPreferences mPreferences = mContext.getSharedPreferences(
                            PREFERENCE_NAME, PREFERENCE_MODE);
            return mPreferences;
    }
    public SharedPreferences getDefaultSharedPreferences(){
            //get SharedData to save in xml with preference activity
            SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
            
            return mPreferences;
    }
    
    public Editor getCustomSharedPreferencesEditor(){
    	//get SharedData to save in xml 
        SharedPreferences mPreferences = mContext.getSharedPreferences(
                            PREFERENCE_NAME, PREFERENCE_MODE);
        
        SharedPreferences.Editor mEditor = mPreferences.edit();
        return mEditor;
    }       
    //GETTER
    public boolean getShowTipDialog(){
    	SharedPreferences mPreferences =  getDefaultSharedPreferences();
    	return mPreferences.getBoolean(NAME_PREFERENCE[0], false);
    }
    //SETTER
    public void setShowTipDialog(boolean isSetDialog){
    	SharedPreferences.Editor mEditor =  getDefaultSharedPreferences().edit();
    	mEditor.putBoolean(NAME_PREFERENCE[0], isSetDialog);
    	mEditor.commit();
    }
  //GETTER
    public int getLanguage(){
    	SharedPreferences mPreferences =  getDefaultSharedPreferences();
    	return mPreferences.getInt(NAME_PREFERENCE[1], 1);
    }
    //SETTER
    public void setLanguage(int index){
    	SharedPreferences.Editor mEditor =  getDefaultSharedPreferences().edit();
    	mEditor.putInt(NAME_PREFERENCE[1], index);
    	mEditor.commit();
    }
  //GETTER
    public String getChatname(){
    	SharedPreferences mPreferences =  getDefaultSharedPreferences();
    	return mPreferences.getString(NAME_PREFERENCE[2], "");
    }
    //SETTER
    public void setChatname(String chatname){
    	SharedPreferences.Editor mEditor =  getDefaultSharedPreferences().edit();
    	mEditor.putString(NAME_PREFERENCE[2], chatname);
    	mEditor.commit();
    }
  //GETTER
    public boolean getShowChatDialog(){
    	SharedPreferences mPreferences =  getDefaultSharedPreferences();
    	return mPreferences.getBoolean(NAME_PREFERENCE[3], false);
    }
    //SETTER
    public void setShowChatDialog(boolean isSetDialog){
    	SharedPreferences.Editor mEditor =  getDefaultSharedPreferences().edit();
    	mEditor.putBoolean(NAME_PREFERENCE[3], isSetDialog);
    	mEditor.commit();
    }

}